


import { Button, Form, Input, Select } from 'antd'
import React from 'react'
import { ajax } from '../../api';
import { toast } from '../../utils/common'
import { inject, observer } from 'mobx-react';

const { Option } = Select;

function OpinionAdd({ user, history }: any) {
    const { userInfo, changeUserInfo }: any = user
    const [form] = Form.useForm()
    const onFinish = async (value: any) => {
        console.log(value)
        let { code, result }: any = await ajax.opinionadd({ ...value, uid: userInfo?._id })
        if (code == 200) {
            form.resetFields()
            history.push("/main/opinion/list")
        }
    }
    const onFinishFailed = () => {
        toast.error("请输入有效的评论")

    }
    return (
        <div style={{ padding: "20px 30px", background: "#fff" }}>
            <h2 style={{ fontSize: '20px' }}>意见箱</h2>
            <div style={{ width: "600px", margin: '30px auto' }}>
                <Form
                    form={form}
                    name="basic"
                    labelCol={{ span: 24 }}
                    wrapperCol={{ span: 24 }}
                    initialValues={{ type: 'noanon' }}
                    onFinish={onFinish}
                    onFinishFailed={onFinishFailed}
                    autoComplete="off"
                >
                    <Form.Item
                        label="标题"
                        name="title"
                        rules={[{ required: true, message: '请输入标题' }]}
                    >
                        <Input allowClear placeholder='为了更高效的处理意见，请输入标题' />
                    </Form.Item>

                    <Form.Item
                        label="内容"
                        name="content"
                        rules={[{ required: true, message: '请输入内容' }]}
                    >
                        <Input.TextArea allowClear autoSize={{ minRows: 6 }} placeholder="请输入内容..." />
                    </Form.Item>

                    <Form.Item
                        label="类型"
                        name="type"
                        rules={[{ required: true, message: '请选择类型' }]}
                    >
                        <Select style={{ width: 120 }}>
                            <Option value="noanon">非匿名</Option>
                            <Option value="anon">匿名</Option>
                        </Select>
                    </Form.Item>

                    <Form.Item>
                        <Button block type="primary" htmlType="submit">
                            提交
                        </Button>
                    </Form.Item>
                </Form>
            </div>
        </div>
    )
}


export default inject("user")(observer(OpinionAdd))